
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;

public class GetDataT {
    public static void main(String[] args) throws IOException {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","192.168.0.85:2181");
        Connection conn = ConnectionFactory.createConnection(conf);
        Table cs = conn.getTable(TableName.valueOf("cs"));
        Scan scan = new Scan();
        ResultScanner rs = cs.getScanner(scan);
        Iterator<Result> it = rs.iterator();

        while (it.hasNext()){
            Result values = it.next();
//            System.out.println(Bytes.toStringBinary(values.getValue("info".getBytes(),"age".getBytes())).equals("null"));
//            System.out.println(Bytes.toStringBinary(values.getValue("info".getBytes(),"age".getBytes())));;
            if(values.containsColumn("info".getBytes(),"age".getBytes())){
                Cell cell = values.getColumnLatestCell("info".getBytes(), "age".getBytes());
//                System.out.println(Bytes.toStringBinary(CellUtil.cloneValue(cell)));
                System.out.println(cell.getValueArray().length);
                Cell cell1 = CellUtil.createCell(CellUtil.cloneRow(cell), CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), cell.getTimestamp(), cell.getTypeByte(), Bytes.toBytesBinary("15"));
                System.out.println(Bytes.toStringBinary(cell.getValue()));
                System.out.println(Bytes.toStringBinary(CellUtil.cloneValue(cell1)));
            }
            /*for(Cell value:values.listCells()){
                String rowKey = Bytes.toStringBinary(CellUtil.cloneRow(value));
                String familyName = Bytes.toStringBinary(CellUtil.cloneFamily(value));
                String qualifierName = Bytes.toStringBinary(CellUtil.cloneQualifier(value));
                String v = Bytes.toStringBinary(CellUtil.cloneValue(value));
                System.out.println(Arrays.toString(CellUtil.cloneRow(value)));
                System.out.println(rowKey+"|"+familyName+"|"+qualifierName+"|"+v);
            }*/
        }
        conn.close();

    }
}
